package com.xoa.controller.nccloud;

import com.alibaba.fastjson.JSON;
import com.xoa.dao.WFE.WFEFlowProcessMapper;
import com.xoa.dao.WFE.WFEFlowTypeModelMapper;
import com.xoa.dao.WFE.WFEFormTypeMapper;
import com.xoa.dao.flowRunFeedback.FlowRunFeedbackMapper;
import com.xoa.dao.flowhook.FlowHookMapper;
import com.xoa.dao.flowplugin.FlowPluginMapper;
import com.xoa.dao.sms.SmsBodyMapper;
import com.xoa.dao.sms.SmsMapper;
import com.xoa.dao.work.WorkMapper;
import com.xoa.dao.workflow.FlowProcessMapper;
import com.xoa.dao.workflow.FlowRunAttachMapper;
import com.xoa.dao.workflow.FlowSortMapper;
import com.xoa.dao.workflow.FlowTiggerMapper;
import com.xoa.dev.workFlow.controller.WorkFlowCreateController;
import com.xoa.model.users.Users;
import com.xoa.model.workflow.FlowFormType;
import com.xoa.model.workflow.TriggerPlugIn;
import com.xoa.plugin.WorkFlowBanckTrigger;
import com.xoa.plugin.WorkFlowRecallTrigger;
import com.xoa.service.WFE.WFEFactory.WFEFlowProcess;
import com.xoa.service.WFE.WFEFactory.WFEFlowType;
import com.xoa.service.WFE.WFEFactory.WFEFormType;
import com.xoa.service.WFE.WFERunner.WFEFlowRun;
import com.xoa.service.WFE.WFERunner.WFEFlowRunPrcs;
import com.xoa.service.work.WorkService;
import com.xoa.util.*;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.session.SessionUtils;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 制单人收回时向NC推送数据处理
 */
@RestController
@RequestMapping(value = "/WorkFlowRecallTrigger/api")
public class WorkFlowRecallController {


    @Autowired
    protected WFEFlowProcessMapper wfeFlowProcessMapper;

    @Autowired
    protected WFEFlowType wfeFlowType;

    @Autowired
    protected WFEFormType wfeFormType;

    @Autowired
    protected WFEFlowProcess wfeFlowProcess;

    @Autowired
    protected WFEFlowRun wfeFlowRun;

    @Autowired
    protected WFEFlowRunPrcs wfeFlowRunPrcs;

    @Autowired
    protected WFEFlowTypeModelMapper wfeFlowTypeModelMapper;

    @Autowired
    protected WFEFormTypeMapper wfeFormTypeMapper;

    @Autowired
    protected WorkMapper workMapper;

    @Autowired
    protected FlowProcessMapper flowProcessMapper;


    @Autowired
    protected FlowTiggerMapper flowTiggerMapper;

    @Autowired
    protected FlowPluginMapper flowPluginMapper;

    @Autowired
    protected FlowHookMapper flowHookMapper;

    @Autowired
    protected FlowRunFeedbackMapper flowRunFeedbackMapper;

    @Autowired
    protected WorkService workService;


    @Autowired
    protected FlowSortMapper flowSortMapper;

    @Autowired
    protected SmsMapper smsMapper;

    @Autowired
    protected SmsBodyMapper smsBodyMapper;

    @Autowired
    protected FlowRunAttachMapper flowRunAttachMapper;

    @Autowired
    protected  WorkFlowCreateController workFlowCreateController;
    @Autowired
    protected WorkFlowRecallTrigger workFlowRecallTrigger;



    @RequestMapping(value = "/recall",method = RequestMethod.POST)
    public ToJson beginSubmit(
            HttpServletRequest httpServletRequest,
            @RequestParam(value = "runId") Integer runId,
            @RequestParam(value = "tabId") String tabId
    )throws Exception{
        //触发器参数提取处公共方法
        TriggerPlugIn triggerPlugIn = new TriggerPlugIn();
        //返回对象信息
        ToJson toJson=new ToJson();
        try {



            triggerPlugIn.setTabId(tabId);
            triggerPlugIn.setRunId(runId.toString());
            toJson=workFlowRecallTrigger.doRun(triggerPlugIn);
            //toJson.setFlag(0);
        }catch (Exception e){
            toJson.setFlag(1);
            toJson.setMsg(e.getMessage());

        }
        return toJson;
    }


}
